// Particle.java (修改后)
package game;

import java.awt.*;

/**
 * 粒子类，用于表示游戏中的粒子效果。
 */
public class Particle {
    float x, y;
    float vx, vy;
    Color color;
    int size;
    float alpha = 1.0f;
    float rotation;
    float rotationSpeed;

    public Particle(int x, int y, float vx, float vy, int hue, int brightness) {
        this.x = x;
        this.y = y;
        this.vx = vx;
        this.vy = vy;
        this.size = (int)(Math.random() * 5 + 2);
        this.color = Color.getHSBColor(hue / 360.0f, 1.0f, brightness / 255.0f);
        this.rotation = (float) (Math.random() * Math.PI * 2);
        this.rotationSpeed = (float) (Math.random() * 0.1 - 0.05);
    }

    public void update() {
        x += vx;
        y += vy;
        vy += 0.1f; // 重力
        alpha -= 0.03f;
        rotation += rotationSpeed;
    }

    public void draw(Graphics g) {
        if (alpha <= 0) return;
        Graphics2D g2d = (Graphics2D) g;

        g2d.rotate(rotation, x + size/2, y + size/2);

        Color drawColor = new Color(
                color.getRed(),
                color.getGreen(),
                color.getBlue(),
                (int)(alpha * 255)
        );
        g2d.setColor(drawColor);
        g2d.fillOval((int)x, (int)y, size, size);

        g2d.rotate(-rotation, x + size/2, y + size/2);
    }
}